package com.wlscale.roadsystem.wiget;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.wlscale.roadsystem.R;


/**
 * 描述: {远程ZigBee信息}
 * 作者: jack-song
 * 创建日期: 2017/11/7 10:04
 * 修改日期: 2017/11/7
 * 版本: {版本}
 */
public class AlterRlterRemoteDstAddressAlertDialog extends Dialog implements View.OnClickListener {
    /**
     * 上下文
     */
    private Context context;
    /**
     * 提示
     */
    private TextView tvTitle;
    /**
     * 左侧按钮
     */
    private Button btnLeft;
    /**
     * 右侧按钮
     */
    private Button btnRigth;
    /**
     * 提示
     */
    private CharSequence title;
    /**
     * 左侧文字
     */
    private CharSequence leftText;
    /**
     * 右侧文字
     */
    private CharSequence rigthText;
    /**
     * 按钮
     */
    private OnClickLister onClickLister;

    public AlterRlterRemoteDstAddressAlertDialog(@NonNull Context context) {
        super(context);
        this.context = context;
    }

    public AlterRlterRemoteDstAddressAlertDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
    }

    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_alter_remote_dst_address);
        tvTitle = findViewById(R.id.tv_title);
        btnLeft = findViewById(R.id.btn_left);
        btnRigth = findViewById(R.id.btn_rigth);
        if (TextUtils.isEmpty(title)) {
            tvTitle.setVisibility(View.GONE);
            tvTitle.setText("");
        } else {
            tvTitle.setVisibility(View.VISIBLE);
            tvTitle.setText(title);
        }
        btnLeft.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(leftText)) {
            btnLeft.setText(leftText);
        }
        btnLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        btnRigth.setVisibility(View.GONE);
        btnRigth.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(rigthText)) {
            btnRigth.setText(rigthText);
        }
        btnRigth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != onClickLister) {
                    onClickLister.onClickLister("");
                }
                dismiss();
            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager wm = window.getWindowManager();
        Point windowSize = new Point();
        wm.getDefaultDisplay().getSize(windowSize);
        window.getAttributes().width = (int) (windowSize.x * 0.8f);
        window.getAttributes().height = ViewGroup.LayoutParams.WRAP_CONTENT;
        window.setGravity(Gravity.CENTER);

    }

    public void setTitle(CharSequence title) {
        this.title = title;
    }


    public void setLeftText(CharSequence leftText) {
        this.leftText = leftText;
    }

    public void setRigthText(CharSequence rigthText) {
        this.rigthText = rigthText;
    }

    public void setOnClickLister(OnClickLister onClickLister) {
        this.onClickLister = onClickLister;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_start_date_picker:
                break;
        }
    }

    public static class Builder {
        /**
         * 上下文
         */
        private Context context;
        /**
         * 提示
         */
        private CharSequence title;
        /**
         * 左侧文字
         */
        private CharSequence leftText;
        /**
         * 右侧文字
         */
        private CharSequence rigthText;
        /**
         * 按钮
         */
        private OnClickLister onClickLister;

        public Builder() {
        }

        public Builder setContext(Context context) {
            this.context = context;
            return this;
        }

        public Builder setTitle(CharSequence title) {
            this.title = title;
            return this;
        }


        public Builder setLeftText(CharSequence leftText) {
            this.leftText = leftText;
            return this;
        }

        public Builder setRigthText(CharSequence rigthText) {
            this.rigthText = rigthText;
            return this;
        }

        public Builder setOnClickLister(OnClickLister onClickLister) {
            this.onClickLister = onClickLister;
            return this;
        }


        public AlterRlterRemoteDstAddressAlertDialog builder() {
            AlterRlterRemoteDstAddressAlertDialog loadingDialog = new AlterRlterRemoteDstAddressAlertDialog(context, R.style.loading_dialog);
            loadingDialog.setTitle(title);
            loadingDialog.setLeftText(leftText);
            loadingDialog.setRigthText(rigthText);
            loadingDialog.setOnClickLister(onClickLister);
            return loadingDialog;
        }
    }

    public interface OnClickLister {
        void onClickLister(String locAddress);
    }

}
